package 算法.贪心算法.股票问题;

public class Main {


	static int getMax3(int[] prices) {
		// 保存利润
		int count = 0;
		int len = prices.length;
		for (int i = 0; i < len; i++) {

			for (int j = i; j < len - 1; j++) {
				// 如果第2天比第1天上涨了
				if (prices[j + 1] > prices[j]) {
					count += prices[j + 1] - prices[j];
					i = j;
				} else {
					i = j;
					break;
				}
			}
		}
		return count;
	}

	public static void main(String[] args) {
		int[] ints = new int[]{7, 1, 5, 3, 6, 4};
		int[] ints2 = new int[]{1, 2, 3, 4, 5};
		int[] ints3 = new int[]{7, 6, 4, 3, 1};
		System.out.println(getMax3(ints)); //7
		System.out.println(getMax3(ints2)); //4
		System.out.println(getMax3(ints3)); //0
	}

}
